package com.tsll.controller;


import com.tsll.entity.Ebook;
import com.tsll.service.BookTypeService;
import com.tsll.service.EbookComService;
import com.tsll.service.EbookService;
import com.tsll.vo.EbookVo;
import com.tsll.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("/ebook")
public class EBookController {
    @Autowired
    private EbookService ebookService;
    @Autowired
    private BookTypeService bookTypeService;
    @Autowired
    EbookComService ebookComService;
    //获取全部电子图书信息,传入分页数据和搜索数据
    @RequestMapping("/list/{current}/{pageSize}")
    public Result list(@PathVariable Integer current, @PathVariable Integer pageSize, @RequestBody EbookVo ebookVo){
        return ebookService.findByPage(current,pageSize,ebookVo);
    }
    //添加电子图书信息
    @RequestMapping("/add")
    public Result add( @RequestBody Ebook ebook){
        return ebookService.insert(ebook);
    }
    //修改电子图书信息
    @RequestMapping("/update")
    public Result update(@RequestBody Ebook ebook){
        return ebookService.update(ebook);
    }
    //根据id删除电子图书信息
    @RequestMapping("/del/{ebookId}")
    public Result del(@PathVariable Integer ebookId){
        return ebookService.delBook(ebookId);
    }
    //获取全部电子图书信息
    @RequestMapping("/getEbook")
    public Result getEbook(){
      return ebookService.getEbook();
    }
    //最近半年内新发布的图书信息
    @RequestMapping("/newDate")
    public Result newDate(){
        return ebookService.AllNewDate();
    }
    //精彩评论内应包含的信息
    @RequestMapping("/rowCom/{bookId}")
    public Result rowCom(@PathVariable Integer bookId){
        return ebookComService.getComById(bookId);
    }
}
